package com.moyu.myadmin;

import lombok.extern.log4j.Log4j2;
import org.camunda.bpm.engine.RepositoryService;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.repository.ProcessDefinition;
import org.camunda.bpm.spring.boot.starter.annotation.EnableProcessApplication;
import org.camunda.bpm.spring.boot.starter.event.PostDeployEvent;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.event.EventListener;

import java.util.List;

@Log4j2
@EnableProcessApplication // 开启 camunda
@SpringBootApplication
public class MyAdminApplication implements CommandLineRunner {

    private final RepositoryService repositoryService;

    public MyAdminApplication(RepositoryService repositoryService) {
        this.repositoryService = repositoryService;
    }

    public static void main(String[] args) {
        SpringApplication.run(MyAdminApplication.class, args);
    }

    @Override
    public void run(String... args) {
        List<ProcessDefinition> processDefinitionList = repositoryService.createProcessDefinitionQuery().active().latestVersion().list();
        log.info("> 处于激活状态的最新版本的流程定义数量: {}", processDefinitionList.size());
        for (ProcessDefinition pd : processDefinitionList) {
            log.info("\t ===> Process definition: " + pd.getKey() + " 版本：" + pd.getVersion());
        }
    }

}
